package com.zzyl.controller;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.RoomDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {

    @Autowired
    NursingProjectService nursingProjectService;


    /**
     * 分页查询合同信息
     * @return 分页结果
     */
    @GetMapping
    @ApiOperation(value = "分页查询护理项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理项目名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query")
    })
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(Integer pageNum,
                                                                       Integer pageSize,
                                                                       String name,
                                                                       Integer status) {

        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @PostMapping
    @ApiOperation("添加项目工程")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("要添加护理项目:{}",nursingProjectDto);
        nursingProjectService.addNursingProject(nursingProjectDto);

        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id) {
        log.info("根据id查询护理项目:{}",id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);

        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("更新护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("要更新护理项目:{}",nursingProjectDto);
        nursingProjectService.updateNursingProject(nursingProjectDto);

        return ResponseResult.success();
    }

    //启用禁用
    @PutMapping("{id}/status/{status}")
    @ApiOperation("启用禁用护理项目")
    public ResponseResult updateStatus(@PathVariable("id") Long id,
                                       @PathVariable("status") Integer status) {
        log.info("启用禁用护理项目id:{},status：{}",id,status);
        nursingProjectService.updateStatus(id,status);

        return ResponseResult.success();
    }

    //删除护理项目
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        log.info("删除护理项目id:{}",id);
        nursingProjectService.deleteById(id);

        return ResponseResult.success();
    }

    //查询所有护理项目
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAll() {
        List<NursingProjectVo> nursingProjectAll = nursingProjectService.getAll();
        return ResponseResult.success(nursingProjectAll);
    }
}
